﻿using System;
using System.Collections.Generic;
using TuxedoLib;

namespace SpaceSquirrel
{
	public static class TileStore
	{
		private static Dictionary<string, TileTemplate> tileStore = null;

		private static void Init()
		{
			tileStore = new Dictionary<string, TileTemplate>();

			AssetLoader loader = AssetLoader.LoadFromProject("images/tiles/manifest.txt", typeof(TileStore).Assembly, false);
			loader.LoadData();
			string[] lines = loader.ConvertDataToText().Split('\n');
			foreach (string line in lines)
			{
				string[] parts = line.Split('#')[0].Trim().Split('\t');
				if (parts.Length == 3)
				{
					string id = parts[0].Trim();
					string flags = parts[1].Trim();
					string[] imagePaths = parts[2].Trim().Split(',');
					TileTemplate tile = new TileTemplate(id, flags, imagePaths);
					tileStore[id] = tile;
				}
			}
		}

		public static TileTemplate GetTile(string id)
		{
			if (tileStore == null)
			{
				Init();
			}
			return tileStore[id];
		}
	}
}
